/*
 * @Author: 深海有鱼 847094299@qq.com
 * @Date: 2025-04-03 22:51:15
 * @LastEditors: 深海有鱼 847094299@qq.com
 * @LastEditTime: 2025-04-18 01:04:53
 * @FilePath: \pure-admin-thin\src\api\adminFileApi.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { http } from "@/utils/http";
import { useStreamDownload } from "@/utils/useStreamDownload";
/** 分页获取所有文件（支持关键词、类型、服务和国家筛选） */
export const getFileList = (params?: {
  page?: number;
  size?: number;
  keyword?: string;
  type?: string;
  serviceType?: string;
  country?: string;
  startDate?: string;
  endDate?: string;
}) => {
  return http.request<any>("get", "/api/admin/files", { params });
};

/** 根据文件ID获取文件下载URL */
export const getFileDownloadUrl = (id: number | string) => {
  return http.request<any>("get", `/api/admin/files/${id}/url`);
};

/** 根据文件ID直接下载文件 */
export const downloadFileById = (id: number | string) => {
  const { download } = useStreamDownload();
  return download(`/api/admin/files/${id}/download`, {
    method: "GET"
  });
};

/** 删除指定文件 */
export const deleteFile = (fileId: number | string) => {
  return http.request<any>("delete", `/api/admin/files/${fileId}`);
};

/** 批量删除文件 */
export const deleteFilesBatch = (data: string[]) => {
  return http.request<any>("delete", "/api/admin/files/batch", { data });
};

/** 获取文件统计信息（可按文件类型筛选） */
export const getFileStats = (params?: { fileType?: string }) => {
  return http.request<any>("get", "/api/admin/files/stats", { params });
};

/** 按服务类型分组获取文件 */
export const getFilesByService = (params?: {
  page?: number;
  size?: number;
  country?: string;
  fileType?: string;
}) => {
  return http.request<any>("get", "/api/admin/files/by-service", { params });
};

/** 按国家分组获取文件 */
export const getFilesByCountry = (params?: {
  page?: number;
  size?: number;
  serviceType?: string;
  fileType?: string;
}) => {
  return http.request<any>("get", "/api/admin/files/by-country", { params });
};
